package com.kova.api.controller;


import com.kova.api.common.Result;
import com.kova.api.exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义异常拦截
 */
//@ControllerAdvice
@Slf4j
@RestControllerAdvice
public class CustomExceptionController {

    //拦截自定义异常错误
    @ExceptionHandler(CommonException.class)
    //@ResponseBody
    public Result customException(CommonException e) {

        log.error("拦截自定义异常exception : {}", e.getMsg());
        return new Result(e.getCode(),e.getMsg(),null);
    }
}
